#!/bin/bash -
#=======================================================================
#
#          FILE: create_wiki_table.sh
#         USAGE: ./create_wiki_table <url>
#   DESCRIPTION: Create wiki table for scripts svn-url
#  REQUIREMENTS: svn
#          BUGS: N/A
#         NOTES: N/A
#        AUTHOR: Ali Ayoub
#         EMAIL: ali@mellanox.com
#       COMPANY: N/A
#       CREATED: 09.17.2010-15:46:13
#      REVISION: 1.0
#=======================================================================

SCRIPT=`basename $0`
USAGE="Usage: $0 <svn-url>"
EXAMPLE="Example: $0 /tmp/scripts"
if [ $# != 1 ]; then
        echo $USAGE
        echo $EXAMPLE
        exit 1
fi

url=$1

dir=/tmp/$$
svn co $url $dir -q
if [ "$?" != "0" ]; then
	echo "-E- command failed: svn co $url $dir"
	exit 1
fi


echo "|| *File Name* || *Description* ||"
for i in `\ls $dir`; do
	desc=`\grep ^# $i | \grep  DESCRIPTION: | head -n1 | cut -d: -f2 | sed -e 's,^\ ,'',g'`
	file=`\grep ^# $i | \grep  FILE:        | head -n1 | cut -d: -f2 | sed -e 's,^\ ,'',g'`

	if [ "$file" == "" ]; then
		continue
	elif [ "$desc" == "" ]; then
		continue
	fi

	link=$url/$file
	echo "|| [$link $file]         || $desc         ||"
done

echo "_This table was generated automatically by running $SCRIPT $1 _"
\rm -rf $dir
